﻿using System;
using System.ServiceModel.DomainServices.Hosting;
using System.ServiceModel.DomainServices.Server.ApplicationServices;
using System.Web.Security;
using MVVMBasicRIALibrary.Web.Models;

namespace MVVMBasicRIALibrary.Web.Services
{
    [EnableClientAccess]
    public class BasicAuthDomainService : AuthenticationBase<User>
    {
        // To enable Forms/Windows Authentication for the Web Application, 
        // edit the appropriate section of web.config file.
        protected override bool ValidateUser(string userName, string password)
        {
            var user = Membership.GetUser(userName);

            if (user != null && !user.IsApproved)
            {
                throw new Exception("NOT_APPROVED");
            }
            return base.ValidateUser(userName, password);
        }

    }
}